#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys,os,socket,time
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import QDeclarativeView
from QtMobility import Sensors
from PySide import QtOpenGL

def netcat(hostname, port, content):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((hostname, port))
    s.sendall(content)
    s.shutdown(socket.SHUT_WR)

class Console(QObject):
	@Slot(str)
	def saveip(self,ip):
		f=open('settings','w').write(ip)
    		print ip



def start():
	screen=QPixmap.grabWindow(QApplication.desktop().winId())
	screen.save('ogapunch',"png")
	f=open('ogapunch','r').read()
	ipa='192.168.69.130'
	os.system("cat ogapunch | nc "+ipa+" 9001")
	#netcat(ipa,9001,f)
	time.sleep(1)
	#screen.save('screen','png')


# Create Qt application and the QDeclarative view & accelerometer
app = QApplication(sys.argv)
view = QDeclarativeView()
view.setResizeMode(QDeclarativeView.SizeRootObjectToView)

# Create an URL to the QML file
url = QUrl('view.qml')
# Set the QML file and show
view.setSource(url)
#define button and signal respnse
root = view.rootObject()
button=root.findChild(QObject,"buttonMouseArea")
con=Console()
context=view.rootContext()
context.setContextProperty("con",con)
button.clicked.connect(lambda: start())

view.showFullScreen()
# Enter Qt main loop
sys.exit(app.exec_())
#help
